home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / uw_1.exe / UW_TUT8.C < prev    next >
Text File  |  1992-11-02  |  19KB  |  490 lines

  1. /****************************************************************************/
  2. /* UW_TUT8.C                                                                */
  3. /*                                                                          */
  4. /* NOTE: THIS FILE IS PUBLIC DOMAIN AND MAY BE MODIFIED AND USED AT WILL    */
  5. /*                                                                          */
  6. /* Now we mouse support for the windows and data entry selection...         */
  7. /* To add mouse we use a cute little trick - we see where the mouse cursor  */
  8. /* is when a button is pressed and map the area to a key.  Processing then  */
  9. /* proceeds just as though you pressed the key.  There are other ways to    */
  10. /* interface to the mouse, this is just one simple method.                  */
  11. /*                                                                          */
  12. /*                                                         Dr. Boyd Gafford */
  13. /*                                                         Kevin Huck       */
  14. /*                                                         EnQue Software   */
  15. /*                                                         09/16/92         */
  16. /****************************************************************************/
  17. #include <stdio.h>
  18. #include <fcntl.h>
  19. #include <io.h>
  20. #ifndef __TURBOC__
  21. #include <sys\types.h>
  22. #endif
  23. #include <sys\stat.h>
  24. #include <time.h>
  25. #include <ctype.h>
  26. #include "uw.h"                           /* include the necessary headers  */
  27.  
  28. #define MAX_CUST 100
  29.  
  30. typedef struct cust
  31. {
  32.   int status;
  33.   int cust_no;
  34.   char business[34];
  35.   char name[34];
  36.   char addr[34];
  37.   char city[34];
  38.   char state[4];
  39.   char zip[10];
  40.   char phone[16];
  41.   char fax[16];
  42.   char date[10];
  43.   char memo[34];
  44.   char unused[26];                                /* round out to 256 bytes */
  45. } CUST;
  46.  
  47. /*----------------------- global window variables --------------------------*/
  48. WINDOW   Desk_wn, Window1;
  49. CUST Customers[MAX_CUST];
  50. char Fname[33];
  51.  
  52. MENU    Top_menu, *Top_mnp = &Top_menu;
  53. MENU    Files_menu, Edit_menu, Print_menu;
  54. MENU    *Drop_mnps[3];
  55.  
  56. PRINT   Print;
  57.  
  58. /*-------------------------------- prototypes ------------------------------*/
  59. int disp_time(void);
  60. void disp_cust(CUST *cp, WINDOW *wnp);
  61. int file_load(CUST *customers);
  62. int file_save(CUST *customers);
  63. int get_fname(char *fname);
  64. void print_cust(CUST *cp, PRINT *p);
  65.  
  66. /*********/
  67. /* ~main */
  68. /*       ********************************************************************/
  69. /*  Demonstrate data entry capability...                                    */
  70. /****************************************************************************/
  71. int main()
  72. {
  73.   int i, ret_val, cust = 0, end_flag = 0, print_stat = 0;
  74.   WINDOW *wnp;
  75.   CUST *cp;
  76.   uchar back_att  = (LIGHTGRAY << 4) | BLACK,
  77.         bdr_att   = (LIGHTGRAY << 4) | BLACK,
  78.         csr_att   = (CYAN << 4) | YELLOW,
  79.         first_att = (LIGHTGRAY << 4) | RED;
  80.  
  81.   wnp = &Window1;                         /* set local window pointer       */
  82.   init_video(80, 25);                     /* init video for 80 x 25 screen  */
  83.   init_clock(0x3333);                     /* init clock irq at 91 tics/sec  */
  84.   init_mouse();                           /* init mouse if available        */
  85.  
  86.   wn_create(0, 0, V_cols-1, V_rows-1, NO_BDR, WN_NORMAL, &Desk_wn);
  87.   link_window(&Desk_wn);
  88.  
  89.   /*------------------------ create the menu system ------------------------*/
  90.   Drop_mnps[0] = &Files_menu;
  91.   Drop_mnps[1] = &Edit_menu;
  92.   Drop_mnps[2] = &Print_menu;
  93.  
  94.   menu_create(0, 0, V_cols - 1, 0, M_HORIZONTAL,
  95.               back_att, bdr_att, csr_att, first_att,
  96.               NO_BDR, WN_NORMAL, Top_mnp);
  97.   item_add( "   Files   ", 1, 3, &Top_menu );
  98.   item_add( "   Edit    ", 2, 3, &Top_menu );
  99.   item_add( "   Print   ", 8, 3, &Top_menu );
  100.  
  101.   menu_create(0, 1, 14, 5, M_VERTICAL,
  102.     back_att, bdr_att, csr_att, first_att,
  103.     SGL_BDR, WN_NORMAL, Drop_mnps[0]);
  104.   item_add( " Load File", 4, 1, &Files_menu );
  105.   item_add( " Save File", 5, 1, &Files_menu );
  106.   item_add( "   Quit   ", 3, 3, &Files_menu );
  107.  
  108.   menu_create(11, 1, 32, 4, M_VERTICAL,
  109.     back_att, bdr_att, csr_att, first_att,
  110.     SGL_BDR, WN_NORMAL, Drop_mnps[1]);
  111.   item_add( " Clear Current", 6, 7, &Edit_menu );
  112.   item_add( " Clear All    ", 7, 7, &Edit_menu );
  113.  
  114.   menu_create(22, 1, 43, 4, M_VERTICAL,
  115.     back_att, bdr_att, csr_att, first_att,
  116.     SGL_BDR, WN_NORMAL, Drop_mnps[2]);
  117.   item_add( " Print Current", 9, 7, &Print_menu );
  118.   item_add( " Print All    ", 10, 7, &Print_menu );
  119.  
  120.   set_idle_func(disp_time);               /* set background clock function  */
  121.  
  122.   wn_create(5, 5, 75, 20, SLD_BDR, WN_POPUP, wnp);
  123.   wn_color(YELLOW, BLUE, wnp);            /* change the window colors       */
  124.   wn_bdr_color(WHITE, BLUE, wnp);         /* change the border's colors     */
  125.   link_window(wnp);
  126.  
  127.   /*------------- initialize first customer as EnQue Software --------------*/
  128.   cp = &Customers[0];
  129.   strcpy(cp->business, "EnQue Software"); 
  130.   strcpy(cp->name, "Kevin Huck & Boyd Gafford");  
  131.   strcpy(cp->addr, "Rt. 1 Box 116C"); 
  132.   strcpy(cp->city, "Pleasant Hill");  
  133.   strcpy(cp->state, "MO");  
  134.   strcpy(cp->zip, "64080"); 
  135.   strcpy(cp->phone, "(816)987-2515"); 
  136.   strcpy(cp->fax, "(816)987-2515");      
  137.   strcpy(cp->date, "09/11/92");      
  138.   strcpy(cp->memo, "BBS 816-358-8990"); 
  139.  
  140.   /*------------------------ initialize the printer ------------------------*/
  141.   if( init_printer("LPT1", NULL, 2048L, 2048L, &Print) )
  142.     print_stat = 1;
  143.  
  144.   menu_set(Top_mnp);
  145.   wn_plst(CENTERED, 3, "Use cursor keypad to select customer", &Desk_wn);
  146.   wn_plst(CENTERED, 4, "or click on cursor buttons at bottom of screen", &Desk_wn);
  147.   wn_plst(CENTERED, 22, "<Up> <Dn>  <PgUp> <PgDn>  <Home> <End>", &Desk_wn);
  148.   while(!end_flag)
  149.   {
  150.     cp = &Customers[cust];
  151.     mv_cs(1,1, wnp);
  152.     wn_printf(wnp, "Customer:%3d", cust+1);
  153.     disp_cust(cp, wnp);
  154.     m_show();
  155.     wait_event();
  156.     m_hide();
  157.     if( Event.is_mouse )
  158.     {
  159.       if( range(0,Event.m_x,11) && (Event.m_y == 0) )
  160.         Event.key = KEY_ALT_F;
  161.       else if( range(11,Event.m_x,22) && (Event.m_y == 0) )
  162.         Event.key = KEY_ALT_E;
  163.       else if( range(22,Event.m_x,33) && (Event.m_y == 0) )
  164.         Event.key = KEY_ALT_P;
  165.  
  166.       else if( range( 7,Event.m_x,47) && (Event.m_y == 9) )
  167.         Event.key = 'B';
  168.       else if( range( 7,Event.m_x,47) && (Event.m_y == 10) )
  169.         Event.key = 'N';
  170.       else if( range( 7,Event.m_x,47) && (Event.m_y == 11) )
  171.         Event.key = 'A';
  172.       else if( range( 7,Event.m_x,47) && (Event.m_y == 12) )
  173.         Event.key = 'C';
  174.       else if( range(50,Event.m_x,59) && (Event.m_y == 12) )
  175.         Event.key = 'S';
  176.       else if( range(61,Event.m_x,71) && (Event.m_y == 12) )
  177.         Event.key = 'Z';
  178.       else if( range( 7,Event.m_x,47) && (Event.m_y == 13) )
  179.         Event.key = 'P';
  180.       else if( range( 7,Event.m_x,47) && (Event.m_y == 14) )
  181.         Event.key = 'F';
  182.       else if( range( 7,Event.m_x,47) && (Event.m_y == 15) )
  183.         Event.key = 'D';
  184.       else if( range( 7,Event.m_x,47) && (Event.m_y == 16) )
  185.         Event.key = 'M';
  186.  
  187.       else if( range( 21,Event.m_x,24) && (Event.m_y == 22) )
  188.         Event.key = KEY_UP;
  189.       else if( range( 26,Event.m_x,29) && (Event.m_y == 22) )
  190.         Event.key = KEY_DN;
  191.       else if( range( 32,Event.m_x,37) && (Event.m_y == 22) )
  192.         Event.key = KEY_PGUP;
  193.       else if( range( 39,Event.m_x,44) && (Event.m_y == 22) )
  194.         Event.key = KEY_PGDN;
  195.       else if( range( 47,Event.m_x,52) && (Event.m_y == 22) )
  196.         Event.key = KEY_HOME;
  197.       else if( range( 54,Event.m_x,58) && (Event.m_y == 22) )
  198.         Event.key = KEY_END;
  199.       else
  200.         Event.key = 0;  
  201.     }
  202.     switch(Event.key)
  203.     {
  204.       /*------------------------- process menus ----------------------------*/
  205.       case KEY_ALT_Q:                                       /* quit program */
  206.         end_flag = 1;
  207.         break;
  208.       case KEY_ALT_F: case KEY_ALT_E: case KEY_ALT_P:
  209.         m_show();
  210.         if( Event.key == KEY_ALT_F )
  211.